﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Prototipo.CMS.Models;

namespace Prototipo.CMS.Areas.Admin.Controllers
{
    public class PostsController : Controller
    {
        public ActionResult Index()
        {
            var posts = Post.GetAll(Server.MapPath("~/App_Data/Posts.xml"));
            return View(posts);
        }

        [HttpGet]
        public ActionResult Novo()
        {
            return View(new Post());
        }

        [HttpPost, ValidateAntiForgeryToken, ValidateInput(false)]
        public ActionResult Novo(Post post)
        {
            if (ModelState.IsValid)
            {
                Post.Save(Server.MapPath("~/App_Data/Posts.xml"), post);

                return RedirectToAction("Index");
            }

            return View(post);
        }
    }
}
